﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

using BeachRunner.Utility;

namespace BeachRunner.BeachRunner
{
    /// <summary>
    /// Speichert und Zeichnet den Level Timer
    /// 
    /// Autor: Mathias Müller
    /// </summary>
    public class TimerManager
    {
        private Vector2 timerPosition;

        private bool isActive;

        /// <summary>
        /// gibt zurück ob der Timer aktiv ist/ setzt den Timer
        /// </summary>
        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }

        public TimerManager()
        {
            timerPosition = new Vector2(Game1.RES_X - 176, -11);
        }

        public void LoadContent( ContentManager contentManager )
        {
        }

        /// <summary>
        /// restliche Zeit
        /// </summary>
        private int timeLeft;

        public int TimeLeft
        {
            get { return (timeLeft * Game1.TIME_PER_TICK)/1000; }
            set 
            { 
                timeLeft = value / Game1.TIME_PER_TICK;
                IsActive = true;
            }
        }

        /// <summary>
        /// stellt die Punkte auf dem Bildschirm dar
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(SpriteBatch spriteBatch)
        {
            if (TimeLeft > 0 && IsActive)
                spriteBatch.DrawString(Game1.Font_m, "TIME LEFT " + TimeLeft, timerPosition, Color.White);
            else if (TimeLeft <= 0 && IsActive)
                spriteBatch.DrawString(Game1.Font_m, "TIME EXPIRED", timerPosition, Color.White);
        }

        public void Update()
        {
            if (timeLeft > 0)
            {
                timeLeft--;
            }
        }

        /// <summary>
        /// Deactiviert den Timer
        /// </summary>
        public void DeactivateTimer()
        {
            timeLeft = 0;
            IsActive = false;
        }
    }
}
